#include "usb.h"


/******************************************************************************
    Function:
        InitializeList

    Description:
        Initialize the head of the list. The caller must allocate the memory
        for the list. This function must be called before the other linked list
        functions can be used.

    Entry:
        LIST_ENTRY* List

    Exit:
        None
******************************************************************************/
void InitializeList (  LIST_ENTRY       *List  )
{
  List->ForwardLink = List;
  List->BackLink    = List;
}




/******************************************************************************
    Function:
        IsListEmpty

    Description:
        Return 'true' is the list contains zero nodes. Otherwise return 'false'
        The list must have been initialized with InitializeList () before using 
        this function.

    Entry:
        LIST_ENTRY* List. Points to the head of the list to test.

    Exit:
        'true' if the list contains zero nodes. Otherwise return 'false'
******************************************************************************/
BOOLEAN IsListEmpty (  LIST_ENTRY  *List  )
{
  return (BOOLEAN)(List->ForwardLink == List);
}



/******************************************************************************
    Function:
        InsertTailList

    Description:
        Insert a node at the end of a doubly linked list. The list must have 
        been initialized with InitializeList before using this function.

    Entry:
        LIST_ENTRY* ListHead.   Head of a a doubly linked list.
        LIST_ENTRY* Entry.      Element to insert at the beginning of list

    Exit:
        None
******************************************************************************/
void RemoveEntryList ( LIST_ENTRY  *Entry )
{
  LIST_ENTRY  *_ForwardLink;
  LIST_ENTRY  *_BackLink;

  _ForwardLink           = Entry->ForwardLink;
  _BackLink              = Entry->BackLink;      
  _BackLink->ForwardLink = _ForwardLink;
  _ForwardLink->BackLink = _BackLink;   

}



/******************************************************************************
    Function:
        InsertTailList

    Description:
        Insert a node at the end of a doubly linked list. The list must have 
        been initialized with InitializeList before using this function.

    Entry:
        LIST_ENTRY* ListHead.   Head of a a doubly linked list.
        LIST_ENTRY* Entry.      Element to insert at the beginning of list

    Exit:
        None
******************************************************************************/
void InsertTailList (  LIST_ENTRY  *ListHead,  LIST_ENTRY  *Entry  )
{
  LIST_ENTRY *_ListHead;
  LIST_ENTRY *_BackLink;

  _ListHead              = ListHead;              
  _BackLink              = _ListHead->BackLink;     
  Entry->ForwardLink     = _ListHead;    
  Entry->BackLink        = _BackLink;       
  _BackLink->ForwardLink = Entry;    
  _ListHead->BackLink    = Entry;       
}

